//文件名：APP_RemoteControl
//功能：远程控制应用程序存放
//创建时间：2021年10月27日
//作者：dowson
//email：dowson.tseng@gmail.com

#ifndef _APP_REMOTE_CONTROL__
#define _APP_REMOTE_CONTROL__
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>


#define SERVER_CMD_BUFFER_SIZE 3
#define SERVER_CMD_BUFFER_NODE_SIZE 512
//远程控制数据类型
//control_mark  |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8| 7 | 6  | 5  | 4  | 3 | 2  | 1 | 0 |
//                                                                                        |锁车|限速 |寻车| 门锁   | 上电  |
//0-1 上下电控制  0：保留 1：上电 2：上高压 3：下电
//2-3门锁：0 初始化，1 闭锁 2 解锁 3 NULL
//4 寻车：0 初始化 1 寻车
//5 限速：0 不限速，1 限速
//6 锁车 0 允许运行，1 禁止运行
struct RemoteControl_struct{
    uint32_t control_mark;//远程控制标志位（位表示控制对象）
    uint8_t limit_speed_size;//限速标志
    uint8_t default_state;//预留标志
};

//CAN总线控制指令发布结构体
typedef struct SendRemoteControlByCAN_struct{
    uint8_t senddata[8];
    uint8_t receiveMark;
    uint8_t sendMark;
}tSendRemoteControl;

typedef struct struct_ServerCmdBuffer
{
    uint8_t data[SERVER_CMD_BUFFER_NODE_SIZE];
    uint16_t data_len;
}tServerCmdBuffer;



#define POWER_ON_BIT 0x03
#define POWER_ON_BIT_BEGIN 0

#define LOCK_MARK_BIT 0x0c
#define LOCK_MARK_BIT_BEGIN 2

#define FIND_CAR_BIT 0x10
#define FIND_CAR_BIT_BEGIN 4

#define SPEED_LIMIT_BIT 0X20
#define SPEED_LIMIT_BIT_BEGIN 5

#define SPEED_EN_BIT 0X40
#define SPEED_EN_BIT_BEGIN 6

#define DEFAULT_CONTROL_PARAM 0x60;
#define INIT_CONTROL_PARAM 0x0000;


typedef enum{CTR_POWER_ON=50,CTR_LOCK_MARK,CTR_FIND_CAR,CTR_SPEED_LIMIT,CTR_SPEED_EN}remoteControlType;
typedef enum{SPEED_NONE,SPEED_LIMIT,SPEED_LOCK,SPEED_UNLOCK}te_speedCommand;


uint8_t ReadRemoteMsgFromLocal(struct RemoteControl_struct* data);
uint8_t SaveRemoteMsg2flash(struct RemoteControl_struct* data);
void RemoteControlInit(void);
uint8_t ControlStateVehicleInit(void);
void RemoteControlDeinit(void);
void RemoteControlHandleMain(void);
uint8_t ControlResultUpload(void);
void RemoteControlSendOut(void);
void CAN_RemoteVehicleStateCallback(uint8_t* can_databuf);

void DownstreamData_Check_Main(void);
void ServerCmdReciveInit(void);
// void ServerCmdCallback(uint8_t* databuf,uint16_t datalen);
void ServerCmdCallback(char *data, uint32_t size);













#endif
